package analizator;

import analizator.Analizator.Atom;

/**
 *
 * @author bufu
 */
public class Caracter implements Atom {

    public int line, column;
    public char value;

    public Caracter(char value, int line, int column) {
        this.value = value;
        this.line = line;
        this.column = column;
    }

    @Override
    public String toString() {
        return "Caracter " + value + " " + line + " " + column;
    }

    public boolean isLetter() {
        return (value >= 'a' && value <= 'z') || (value >= 'A' && value <= 'Z');
    }

    public boolean isCifra() {
        return (value >= '0' && value <= '9');
    }

    public boolean isHexa() {
        return (value >= 'a' && value <= 'f') || (value >= 'A' && value <= 'F');
    }

    public boolean isSpace() {
        return value == ' ' || value == '\t' || value == '\n' || value == '\r';
    }

    public int intValue() {
        if (isCifra()) {
            return value - '0';
        } else if (value >= 'a' && value <= 'f') {
            return value - 'a' + 10;
        } else if (value >= 'A' && value <= 'F') {
            return value - 'A' + 10;
        } else {
            return -1;
        }
    }

    public boolean validForBase(int base) {
        int valoare = intValue();
        return valoare >= 0 && valoare < base;
    }
}
